(function () {
    angular.module('vehicleCheckApp').controller('UpdateCtrl', ['$scope','$state', '$stateParams', '$ionicLoading', 
	'_vehicleData','_$toast', UpdateCtrl]);

    function UpdateCtrl($scope, $state, $stateParams, $ionicLoading, _vehicleData,_$toast) {
		console.log($stateParams);
		$scope.warehouseName = $stateParams.warehouseName;
		$scope.actno = localStorage.getItem("actno");
		
        $scope.logout= function(){
			var actno = localStorage.getItem("actno");
			localStorage.clear();
			localStorage.actno = actno;
			$state.go("login");
        }         
		
		$scope.update = function(){
			$ionicLoading.show({
				template: '正在更新数据，请耐心等待~'
			});
			_vehicleData.getAllData().then(function(){
				$ionicLoading.hide();
			});
		}

        $scope.changePwd = function(user){
            if(user.newPwd != user.newPwdSecond){
                _$toast.showShortCenter("密码输入必须一致");
            }else{
                var params = {};
                params.userCode = localStorage.actno;
                params.oldPwd = faultylabs.MD5(user.oldPwd);
                params.newPwd = faultylabs.MD5(user.newPwd);
                console.log(params);
                _vehicleData.changePwd(params).then(function(result){
                    _$toast.showShortCenter("修改密码成功");
                },function(result){
                    _$toast.showShortCenter(result.msg);
                });
            }

        }
    };
})();
